<template>
	<view class="content indexC">
		<z-paging ref="paging" @onRefresh="refresh" show-refresher-update-time fixed v-if="false"
							:refresher-end-bounce-enabled="false" :safe-area-inset-bottom="true" :refresher-only="true" >
			<view class="index-clock">
					<image style="width: 120rpx;height: 120rpx" src="../../static/img/tips.svg" mode="widthFix"></image>
					<text style="margin-left: 10rpx">请先授权登录</text>
				<text class="auth-text" @click="authLoginBtn">一键授权</text>
			</view>
			<!--<text v-if="code" style="margin-left: 10rpx">{{code}}</text>-->
		</z-paging>
		<lzLoading :showloading='showLoading' title="登录中..."></lzLoading>
	</view>
</template>

<script>
	import lzLoading from '@/components/lz-loading/lz-loading.vue';

	export default {
		components: {
			lzLoading
		},
		data() {
			return {
				showLoading: true,
				userInfo: '', //用户信息
				messageCont: 0, //未读消息
				account: null,
				passWord: null,
				isRole: false,
				title: "登录中...",
				code: ''
			};
		},
		onLoad() {
		},
		onShow() {
			this.codeLoginAct();
			// this.codeCopy();
		},
		methods: {
			//授权登录
			authLoginBtn() {
				let currentUrl = window.location.href;
				var index = currentUrl.indexOf('?');
				if (index != -1) {
					currentUrl = currentUrl.substring(0, index);
				}
				window.location.href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wl6e538311bc&redirect_uri=' + currentUrl + '&response_type=code&scope=SCOPE&agentid=1001112&state=STATE#wechat_redirec';
			},

			refresh(){
				this.$refs.paging.complete(false);
			},
			//code 复制
			codeCopy() {
				var query = this.$route.query;
				if (query && query.code) {
					let code = query.code;
					this.code = code;
					uni.showModal({
						content: this.code,
						confirmText: '复制内容',
						success: () => {
								this.$copyText(code).then((res) => {
									console.log(res);
									uni.showToast({
										title: "复制成功！",
										duration: 2000,
										icon: "none",
									});
								});
						}
					});
				}
			},
			codeLoginAct() {
				let page=this;
				var query = this.$route.query;
				this.code = '';
				if (query && query.code) {
					let code = query.code;
					this.code = code;
					this.showLoading = true;
					page.$api.codeLogin({
						code: code
					}, true, (res) => {
					// page.$api.normalLogin({
					// 		username:"86474789",
					// 		pwd: "Zmg.wantusui123"
					// 	}, true, (res) => {
							page.showLoading = false;
							console.log(res);
							page.userInfo = res;
							uni.setStorageSync('USERINFO', res);
							//保存用户登录状态
							uni.setStorageSync('TOKEN', res.token);
							uni.showToast({
								title: '登录成功'
							});
							let sett = setTimeout(() => {
											uni.switchTab({
												url: '../index/index'
											});
							}, 1000);
						// uni.showModal({
						// 	title: '返回',
						// 	content: ''+JSON.stringify(res),
						// 	confirmText: '复制内容',
						// 	success: function (s) {
						// 		page.$copyText(JSON.stringify(res)).then((res) => {
						// 			uni.showToast({
						// 				title: "复制成功！",
						// 				duration: 2000,
						// 				icon: "none",
						// 			});
						// 		});
						// 		page.userInfo = res;
						// 		uni.setStorageSync('USERINFO', page.userInfo);
						// 		//保存用户登录状态
						// 		uni.setStorageSync('TOKEN', res.token);
						// 		let sett = setTimeout(() => {
						// 			uni.showToast({
						// 				title: '登录成功'
						// 			});
						// 			uni.switchTab({
						// 				url: '../index/index'
						// 			});
						// 		}, 1000);
						//
						// 	}
						// });
					}, (error) => {
						this.showLoading = false;
					});
				}else {
					this.authLoginBtn()
				}
			}
		}
	};
</script>

<style lang="scss" scoped>
	.indexC {
		letter-spacing: 1rpx;
		background: white;
		width: 100%;

		.user-company {
			width: 92%;
			padding: 70rpx 4% 30rpx 4%;
			background: #fff;
			text-align: left;
			font-weight: bold;
		}

		.index-info {
			background: #fff;
			border-radius: 15rpx;
			width: 84%;
			padding: 30rpx 4%;
			margin: auto;
			margin-top: 30rpx;

			image {
				width: 100rpx;
				height: 100rpx;
				margin-right: 20rpx;
				border-radius: 7rpx;
			}

			.info-text {
				font-weight: bold;
				color: #454545;

				text {
					display: block;

					&:last-child {
						margin-top: 15rpx;
						font-weight: 500;
						color: #454545;
					}
				}
			}
		}

		.index-btn {
			background: #fff;
			border-radius: 15rpx;
			width: 84%;
			padding: 30rpx 4%;
			margin: auto;
			margin-top: 30rpx;

			.btn-item {
				width: 45%;
				font-weight: 500;
				color: #454545;

				image {
					width: 44rpx;
					height: 44rpx;
					display: block;
					margin-right: 15rpx;
				}

				.index-tip {
					background: #E01915;
					border-radius: 50rpx;
					padding: 2rpx 10rpx;
					color: #FFFFFF;
					margin-left: 10rpx;
				}
			}
		}

		.index-clock {
			border-radius: 15rpx;
			width: 84%;
			padding: 20rpx 4% 20rpx 4%;
			margin: auto;
			margin-top: 80rpx;
			display:flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			.auth-text{
				margin-top: 200rpx;
				background: #008AFF;
				color: white;
				text-align: center;
				line-height: 350rpx;
				font-size: 60rpx;
				height: 350rpx;
				width: 300rpx;
				border-radius: 600rpx;
				padding-left: 20rpx;
				padding-right: 20rpx;
			}
		}
	}
</style>
